package cn.zz.veggie.web.controller.mgmt;

import java.util.List;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import cn.zz.comm.core.types.query.PageQuery;
import cn.zz.comm.core.types.result.PageResult;
import cn.zz.comm.web.annotation.BoxRespResult;
import cn.zz.veggie.application.service.QuoteAppService;
import cn.zz.veggie.web.types.dto.mgmt.MgmtQuoteQueryDto;
import cn.zz.veggie.web.types.dto.mgmt.MgmtUserQuotePriceDto;
import cn.zz.veggie.web.types.dto.mgmt.MgmtUserQuoteSaveDto;
import cn.zz.veggie.web.types.vo.mgmt.MgmtProductQuoteVo;
import cn.zz.veggie.web.types.vo.mgmt.MgmtQuoteVo;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.Positive;
import lombok.RequiredArgsConstructor;

/**
 * @author zhongq
 * @since 2024/5/22
 */
@Validated
@BoxRespResult
//@RestController
@RequiredArgsConstructor
@RequestMapping("/mgmt/quote")
public class MgmtQuoteController {

	private final QuoteAppService quoteAppService;

	/**
	 * 报价列表
	 */
	@GetMapping("")
	public PageResult<MgmtQuoteVo> list(@Validated MgmtQuoteQueryDto dto,
										@RequestParam(defaultValue = "1") @Positive Integer current,
										@RequestParam(defaultValue = "10") @Positive Integer size) {
		return quoteAppService.adminGetList(dto, PageQuery.of(current, size));
	}

	/***
	 * 新增报价
	 */
	@PostMapping("")
	public void save(@RequestBody @Validated MgmtUserQuoteSaveDto dto) {
		quoteAppService.adminSaveQuote(dto);
	}

	/**
	 * 修改报价
	 */
	@PutMapping("")
	public void price(@RequestBody @Validated MgmtUserQuotePriceDto dto) {
		quoteAppService.adminChangeQuote(dto);
	}

	/**
	 * 通过商品名以及价格
	 */
	@GetMapping("/products")
	public List<MgmtProductQuoteVo> products(@RequestParam @Positive Integer uid,
			@RequestParam @NotEmpty List<String> product) {
		return quoteAppService.adminGetProductList(uid, product);
	}

}